function ajaxselect(type) {
	var dto = {
		searcher : " where type='"+type+"'",
		pageSize:100,
		pageIndex:1
	};
	$.ajax({
		url : "/xinleju/select.do?pageSize="+dto.pageSize+"&pageIndex="+dto.pageIndex+"&searcher="+dto.searcher,
		type : "POST",
		dataType : "json",
		async : false,
		contentType : "application/json;charset=utf-8",
		//data : dto,
		success : function(data) {
			// if (data.d.Success == true) {}
			// var json = JSON.stringify(data);
			//alert(dto);
			jsons = StrtoObj(data);
			// alert(jsons);
			// alert(JSON.stringify(jsons));
			// eval("var theJson = "+jsons);
			// 附上模板
			$("#pResult").setTemplateElement("pTemplate");
			// 给模板加载数据
			$("#pResult").processTemplate(jsons);
		}
	});
}
//遍历div里所有的input元素
function pdatas(divname){  
divname="#"+divname;
	var postdata ="{";
	//$(divname).find("input[type=text]");
 for(var i=0;i<$(divname).find("input[type=text]").length;i++)
	 {
	 postdata += $(divname).find("input[type=text]")[i].id.toString();
	 postdata +=":";
	 postdata +="\"";
     postdata +=$(divname).find("input[type=text]")[i].value.toString();
     postdata +="\"";
     postdata +=",";
	// alert(postdata);
	 }
    postdata =postdata.substring(0,postdata.length-1); 
	postdata +="}";
	//alert(postdata);
	return postdata;
}

//遍历div里所有的子元素
function pdata(divname){  
divname="#"+divname;
	var postdata ="{";
 for(var i=0;i<$(divname).children().length;i++)
	 {
	 postdata += $(divname).children()[i].id.toString();
	 postdata +=":";
	 postdata +="\"";
     postdata +=$(divname).children()[i].value.toString();
     postdata +="\"";
     postdata +=",";
	 }
    postdata =postdata.substring(0,postdata.length-1); 
	postdata +="}";
	//alert(postdata);
	return postdata;
}
//添加数据到数据库
function add(divname,addtype){  
    $.ajax({  

	contentType : "application/json;charset=utf-8",
    type:"Post",  
    dataType: 'json',  
    data: JSON.stringify({id:0,name:pdatas(divname),type:addtype}),  
	//url:"http://www.xinleju.cn/xinleju/add.do", 
     url:"/xinleju/add.do",  
     error:function(data){  
        alert("出错了！！");  
     },  
    success:function(data){  
	            alert('提交成功！请等待我们与您联系');
         //alert("添加成功！");
     }  
     });  
 } 
//添加数据到数据库
function update(divname,addtype){  
	var ids =$("#id").val();
	var postjson ={id:Number(ids),name:pdata(divname),type:addtype}; 
    //  alert(JSON.stringify(postjson)); return ;
    $.ajax({  

	contentType : "application/json;charset=utf-8",
    type:"Post",  
    dataType: 'json',  
    data: JSON.stringify(postjson),  
     url:"/xinleju/update.do",  
     error:function(data){  
        alert("出错update"+divname+"|"+addtype);  
     },  
    success:function(data){  
         alert("修改成功！");
     }  
     });  
 } 
//添加数据到数据库
function del(){  
	var ids =$("#id").val();
	var postjson ={id:Number(ids)}; 
    $.ajax({  
	contentType : "application/json;charset=utf-8",
    type:"Post",  
    dataType: 'json',  
    data: JSON.stringify(postjson),  
     url:"/xinleju/delete.do",  
     error:function(data){  
        alert("出错update"+divname+"|"+addtype);  
     },  
    success:function(data){  
         alert("删除成功！");
     }  
     });  
 } 
function StrtoObj(strs) {
	for (var i = 0; i < strs.rows.length; i++) {
		eval("var theName = " + strs.rows[i].name);
		//var newName =JSON.stringify(theName);
		eval(strs.rows[i].name = theName);
	}
	//str.replace('\\','');
	//console.log(JSON.stringify(strs));
	return strs;
}
